package com.jiot.controller.device;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.DeviceAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.device.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author hushi
 * @date 2020/11/19 16:34
 * @description
 */
@RestController
@RequestMapping("/device/admin")
@Api(value = "设备模块")
public class DeviceAdminController {

    @Resource
    private DeviceAdminService deviceAdminService;

    @PostMapping("/add/device")
    @TokenCheck
    @ApiOperation(value = "设备添加", notes = "device")
    public BaseResponse addDevice(@RequestBody @Valid AddDeviceReq addDeviceReq) {
        deviceAdminService.addDevice(addDeviceReq);
        return new BaseResponse();
    }

    @PostMapping("/del/device")
    @TokenCheck
    @ApiOperation(value = "删除设备", notes = "device")
    public BaseResponse delDevice(@RequestBody @Valid DelDeviceReq delDeviceReq) {
        deviceAdminService.delDevice(delDeviceReq);
        return new BaseResponse();
    }

    @PostMapping("/modify/device")
    @TokenCheck
    @ApiOperation(value = "设备修改", notes = "device")
    public BaseResponse modifyDevice(@RequestBody @Valid ModifyDeviceReq modifyDeviceReq) {
        deviceAdminService.modifyDevice(modifyDeviceReq);
        return new BaseResponse();
    }

    @PostMapping("/backstage/detail/device")
    @TokenCheck
    @ApiOperation(value = "后台设备详情", notes = "device")
    public BaseResponse backstageDetailDevice(@RequestBody @Valid BackstageDetailDeviceReq backstageDetailDeviceReq) {
        return new BaseResponse(deviceAdminService.backstageDetailDevice(backstageDetailDeviceReq));
    }


    @PostMapping("/select/device/by/user/area")
    @TokenCheck
    @ApiOperation(value = "根据用户区域值查询设备", notes = "device")
    public BaseResponse selectDeviceByUserArea(@RequestBody @Valid SelectDeviceByUserAreaReq selectDeviceByUserAreaReq) {
        return new BaseResponse(deviceAdminService.selectDeviceByUserArea(selectDeviceByUserAreaReq));
    }
}
